#include <stdio.h>
#include <stdlib.h>

#define SIZE 10

typedef struct
{
    char data[SIZE];
    int top;
} Strack;

Strack *init()
{
    Strack item;

    item.top = -1;

    Strack *address = &item;

    printf("init address=%p \n", address);

    return address;
}

// 入栈
void push(Strack *strack, char item)
{
    int top = strack->top;

    int index = top + 1;
    printf("push strack index=%d \n", index);

    strack->top = index;
    strack->data[index] = item;
}

// 打印当前栈
void printStrack(Strack *strack)
{
    int top = strack->top;

    for (int i = 0; i <= top; i++)
    {
        char c = strack->data[i];
        printf("print strack item=%c \n", c);
    }
}
// 出栈
char pop(Strack *strack)
{
    int index = strack->top;

    char result = strack->data[index];
    strack->top = index - 1;

    return result;
}

void main()
{
    Strack *item = init();

    push(item, 'b');
    push(item, 'b');
    push(item, 'c');
    push(item, 'd');
    push(item, 'e');

    printStrack(item);

    char c = pop(item);
    printf("pop char c=%c \n",c);
    printf("----------pop after---------- \n");
    char d = pop(item);
    printf("pop char d=%c \n",d);
}
